package com.glureau.aib.client;

import com.glureau.aib.client.ai.AiTable;
import com.glureau.aib.client.auth.NewAccountLoginPage;
import com.glureau.aib.client.equipe.PionTable;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Aib_webapp implements EntryPoint, GlobalObserverInterface {

	private final static String CONTAINER_NAME = "mainContainer";
	private NewAccountLoginPage m_newAccountLoginPage;
	private PionTable m_pions;
	private AiTable m_ais;

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		RootPanel.get("loading").setVisible(false);
		m_newAccountLoginPage = new NewAccountLoginPage(this);
		RootPanel.get(CONTAINER_NAME).add(m_newAccountLoginPage.getWidget());
	}

	private void createView() {
		m_pions = new PionTable();
		m_pions.init();
		RootPanel.get(CONTAINER_NAME).add(m_pions.getWidget());
		
		m_ais = new AiTable();
		m_ais.init();
		RootPanel.get(CONTAINER_NAME).add(m_ais.getWidget());
	}

	@Override
	public void globalNotify(NOTIFICATION notification, Object... param) {
		System.err.println("NOTIFICATION RECEIVED : " + notification.name());
		switch (notification) {
		case AUTHENTICATED:
			createView();
			break;
		case DEAUTHENTICATED:
			RootPanel.get(CONTAINER_NAME).remove(m_pions.getWidget());
			break;
		default:
			break;
		}
		System.err.println("NOTIFICATION CHECKED : " + notification.name());
	}
}
